package service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.rain.constant.Constants;
import com.rain.models.account.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.AccountService;
import service.LoginService;

import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private AccountService accountService;

    /**
     * 校验用户名密码登录有效性 密码通过SHA256加密
     * @param loginName
     * @param password
     * @return
     */
    @Override
    public boolean checkLogin(String loginName, String password) {
        boolean flag = false;
        List<Account> list = accountService.list(Wrappers.<Account>lambdaQuery().eq(Account::getDeleteFlag, Constants.INT_ZERO).eq(Account::getLoginName, loginName).eq(Account::getPassword, password));
        if (CollectionUtils.isNotEmpty(list)) {
            flag = true;
        }
        return flag;
    }
}
